package com.stylefeng.guns.modular.hhtb.controller;

import com.baomidou.mybatisplus.plugins.Page;
import com.stylefeng.guns.core.base.controller.BaseController;
import com.stylefeng.guns.core.common.constant.factory.PageFactory;
import com.stylefeng.guns.modular.hhtb.model.LogMailccDto;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.beans.factory.annotation.Autowired;
import com.stylefeng.guns.core.log.LogObjectHolder;
import org.springframework.web.bind.annotation.RequestParam;
import com.stylefeng.guns.modular.hhtb.model.LogMailcc;
import com.stylefeng.guns.modular.hhtb.service.ILogMailccService;

import java.util.List;
import java.util.Map;

/**
 * 用户消费账户流水控制器
 *
 * @author fengshuonan
 * @Date 2018-08-27 14:00:08
 */
@Controller
@RequestMapping("/logMailcc")
public class LogMailccController extends BaseController {

    private String PREFIX = "/hhtb/logMailcc/";

    @Autowired
    private ILogMailccService logMailccService;

    /**
     * 跳转到用户消费账户流水首页
     */
    @RequestMapping("")
    public String index() {
        return PREFIX + "logMailcc.html";
    }

    /**
     * 跳转到添加用户消费账户流水
     */
    @RequestMapping("/logMailcc_add")
    public String logMailccAdd() {
        return PREFIX + "logMailcc_add.html";
    }

    /**
     * 跳转到修改用户消费账户流水
     */
    @RequestMapping("/logMailcc_update/{logMailccId}")
    public String logMailccUpdate(@PathVariable Integer logMailccId, Model model) {
        LogMailcc logMailcc = logMailccService.selectById(logMailccId);
        model.addAttribute("item",logMailcc);
        LogObjectHolder.me().set(logMailcc);
        return PREFIX + "logMailcc_edit.html";
    }

    /**
     * 获取用户消费账户流水列表
     */
    @RequestMapping(value = "/list")
    @ResponseBody
    public Object list(LogMailccDto logMailccDto) {
        Page<Map<String,Object>> page = new PageFactory<Map<String,Object>>().defaultPage();
        List<Map<String, Object>> articlesList= logMailccService.selectLogMailcList(page,logMailccDto);
        page.setRecords(articlesList);
        return super.packForBT(page);
    }

    /**
     * 新增用户消费账户流水
     */
    @RequestMapping(value = "/add")
    @ResponseBody
    public Object add(LogMailcc logMailcc) {
        logMailccService.insert(logMailcc);
        return SUCCESS_TIP;
    }

    /**
     * 删除用户消费账户流水
     */
    @RequestMapping(value = "/delete")
    @ResponseBody
    public Object delete(@RequestParam Integer logMailccId) {
        logMailccService.deleteById(logMailccId);
        return SUCCESS_TIP;
    }

    /**
     * 修改用户消费账户流水
     */
    @RequestMapping(value = "/update")
    @ResponseBody
    public Object update(LogMailcc logMailcc) {
        logMailccService.updateById(logMailcc);
        return SUCCESS_TIP;
    }

    /**
     * 用户消费账户流水详情
     */
    @RequestMapping(value = "/detail/{logMailccId}")
    @ResponseBody
    public Object detail(@PathVariable("logMailccId") Integer logMailccId) {
        return logMailccService.selectById(logMailccId);
    }
}
